import * as _ from 'lodash';
import * as process from 'process';
import { registerAs } from '@nestjs/config';
import defaultCfg from './config.default';
import developmentCfg from './config.dev';
import productionCfg from './config.prod';
import betaCfg from './config.beta';
import dailyCfg from './config.daily';

const envConfigMap = {
  development: developmentCfg,
  production: productionCfg,
  beta: betaCfg,
  daily: dailyCfg,
};

const Config = _.merge(defaultCfg, envConfigMap[process.env.NODE_ENV]);

// server配置
const serverCfg = registerAs('server', () => Config.server);
// static配置
const staticCfg = registerAs('static', () => Config.static);
// database配置
const databaseCfg = registerAs('database', () => Config.database);
// common配置
const commonCfg = registerAs('common', () => Config.common);
// 日志配置
const logCfg = registerAs('log', () => Config.log);
// redis配置
const redisCfg = registerAs('redis', () => Config.redis);
// 邮箱配置
const emailCfg = registerAs('email', () => Config.email);
// 限流配置
const throttlerCfg = registerAs('throttler', () => Config.throttler);
// jwt配置
const jwtCfg = registerAs('jwt', () => Config.jwt);
export default [
  serverCfg,
  commonCfg,
  staticCfg,
  databaseCfg,
  logCfg,
  redisCfg,
  emailCfg,
  throttlerCfg,
  jwtCfg,
];
